package com.example;

import java.util.List;
import java.util.Map;
import java.util.Vector;

import com.example.priorityobserver.Observable;
import com.example.priorityobserver.Observer;
import com.example.sensors.AbstractSensor;
import com.example.sensors.Sensor_Accelometer;
import com.example.sensors.Sensor_Audio;
import com.example.sensors.Sensor_GPS;
import com.example.sensors.Sensor_Orientation;
import com.example.sensors.Sensor_PhoneLock;
import com.example.sensors.Sensor_Phone_Calls;
import com.example.sensors.Sensor_Power;
import com.example.sensors.Sensor_Screen;
import com.example.sensors.Sensor_Transport_Mode;
import com.example.sensors.Sensor_Wired_Headset;

public class MySensorManager extends Observable<Map<String, Object>> {
	private static MySensorManager instance = null;

	public Sensor_GPS mSensor_GPS;
	public Sensor_Power mSensor_Power;
	public Sensor_Accelometer mSensor_Accelometer;
	public final Sensor_Wired_Headset mSensor_Wired_Headset;
	public Sensor_Transport_Mode mSensor_Transport_Mode;
	public Sensor_Orientation mSensor_Orientation;
	public Sensor_Screen mSensor_Screen;
	public Sensor_Audio mSensor_Audio;
	public Sensor_PhoneLock mSensor_PhoneLock;
	// public final Sensor_running_applications mSensor_running_applications;
	public Sensor_Phone_Calls mSensor_Phone_Calls;
	String[] mLargEventSQLData = new String[3];
	List<AbstractSensor> availableSensors;

	// private final Sensor_Launched_Apps mSensor_Launched_Apps;

	protected MySensorManager() {
		availableSensors = new Vector<AbstractSensor>();
		mSensor_Wired_Headset = new Sensor_Wired_Headset();
		mSensor_GPS = new Sensor_GPS();
		mSensor_Power = new Sensor_Power();
		mSensor_Accelometer = new Sensor_Accelometer();
		mSensor_Transport_Mode = new Sensor_Transport_Mode(mSensor_GPS,
				mSensor_Accelometer);
		mSensor_Orientation = new Sensor_Orientation();
		mSensor_Screen = new Sensor_Screen();
		// mSensor_running_applications = new Sensor_running_applications(this);
		mSensor_Phone_Calls = new Sensor_Phone_Calls();
		mSensor_Audio = new Sensor_Audio();
		mSensor_PhoneLock = new Sensor_PhoneLock(mSensor_Screen);
		// mSensor_Launched_Apps = new Sensor_Launched_Apps(this);
		availableSensors.add(mSensor_Wired_Headset);
		availableSensors.add(mSensor_Transport_Mode);
		availableSensors.add(mSensor_GPS);
		availableSensors.add(mSensor_Accelometer);
		availableSensors.add(mSensor_Orientation);
		availableSensors.add(mSensor_PhoneLock);
		availableSensors.add(mSensor_Screen);
		// availableSensors.add(mSensor_Phone_Calls);
		availableSensors.add(mSensor_Audio);
		availableSensors.add(mSensor_Power);
	}

	public static MySensorManager getInstance() {
		if (instance == null) {
			instance = new MySensorManager();
		}
		return instance;
	}

	public void disableAllSensors() {
		for (AbstractSensor i : availableSensors)
			i.disableSensor();
	}

	public void enableAllSensors() {
		for (AbstractSensor i : availableSensors)
			i.enableSensor();
	}

	public void handleSensors(String mEvent) {

	}

	@Override
	public void registerObserver(Observer<Map<String, Object>> observer) {
		for (AbstractSensor i : availableSensors) {
			i.registerObserver(observer);
		}
	}

	@Override
	public void registerObserverFirst(Observer<Map<String, Object>> observer) {
		for (AbstractSensor i : availableSensors) {
			i.registerObserverFirst(observer);
		}
	}

	@Override
	public void registerObserverEnd(Observer<Map<String, Object>> observer) {
		for (AbstractSensor i : availableSensors) {
			i.registerObserver(observer);
		}
	}
}
